﻿using System;
using System.Web.Mvc; 
namespace XSTDZ.ERP.Infrastructure.Authentication
{
    public class AuthenticationDefaultControllerFactory : DefaultControllerFactory   
    {
        protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType)
        {
            
            requestContext.HttpContext.Response.BufferOutput = true;
            IController instance = null;
            //try
            //{
                instance = base.GetControllerInstance(requestContext, controllerType);
            //}
            //catch (Exception ex)
            //{
              
            //}
           
            if (instance != null && typeof(Controller).IsAssignableFrom(controllerType))
            {
                Controller controller = (Controller)instance;
                //依赖注入  
                controller.ActionInvoker = new DefaultControlActionInvoker();
                //controller.  
                return controller;
            }
            else
            {
                return instance;
            }
        }
    }
}
